<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true"><block slot="backText"></block><block slot="content"></block></cu-custom>
		<view v-if="isCanUse">
		    <view>
		        <view class='header'>
		            <image src="../../static/images/logo_lianjiu.png" style="width:170upx;height:400upx;" mode="aspectFit"></image>
		        </view>
		        <view class='content'>
		            <view>申请获取以下权限</view>
		            <text>获得你的公开信息(昵称，头像、地区等)</text>
		        </view>
		        <button class='bottom' type='primary' open-type="getUserInfo" withCredentials="true" lang="zh_CN" @getuserinfo="wxGetUserInfo">
		            授权登录
		        </button>        
		    </view>
		</view>
	</view>
</template>

<script>
	import { Login,SendSMSCode } from '@/api/user.js'
    export default {
        data() {
            return {
                SessionKey: '',
                OpenId: '',
                nickName: null,
                avatarUrl: null,
                isCanUse: uni.getStorageSync('isCanUse')||true//默认为true
            };
        },
		onShow() {
			// if(uni.getStorageSync('isCanUse') == 1){
			// 	uni.navigateTo({
			// 		url:'./register'
			// 	})
			// }
		},
        methods: {
            wxGetUserInfo() {
                let _this = this;
                uni.getUserInfo({
                    provider: 'weixin',
                    success: (res)=> {
                        let nickName = res.userInfo.nickName; //昵称
                        let avatarUrl = res.userInfo.avatarUrl; //头像
                        try {
                            uni.setStorageSync('isCanUse', 1);//记录是否第一次授权  false:表示不是第一次授权
                        } catch (e) {}
						uni.redirectTo({
							url:'./login'
						})
                    },
                    fail(res) {}
                });
            }
        },
        onLoad() {//默认加载
            // this.login();
        }
    }
</script>

<style lang="scss">
	/deep/page{
		background-color: #fff;
	}
.header {
        margin: 90rpx 0 90rpx 50rpx;
        border-bottom: 1px solid #ccc;
        text-align: center;
        width: 650rpx;
        height:400rpx;
        line-height: 450rpx;
    }

    .header image {
        width: 200rpx;
        height: 200rpx;
    }

    .content {
        margin-left: 50rpx;
        margin-bottom: 90rpx;
    }

    .content text {
        display: block;
        color: #9d9d9d;
        margin-top: 40rpx;
    }

    .bottom {
        border-radius: 80rpx;
        margin: 70rpx 50rpx;
        font-size: 35rpx;
    }
</style>
